package com.marry.consumer.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @author ml
 * @create 2017-08-03--16:12
 */
@Configuration
@PropertySource(value = {"classpath:mail.properties"})
public class MailConfig {

    @Autowired
    private Environment env;


    @Bean
    public JavaMailSender javaMailSender(){
        JavaMailSenderImpl javaMailSender=new JavaMailSenderImpl();

        // 如果为普通邮箱, 非ssl认证等
        javaMailSender.setHost(env.getProperty("mail.host"));

        javaMailSender.setPort(Integer.parseInt(env.getProperty("mail.port")));

        javaMailSender.setUsername(env.getProperty("mail.username"));

        javaMailSender.setPassword(env.getProperty("mail.password"));

        javaMailSender.setDefaultEncoding("utf-8");

        Properties prop=new Properties();
        prop.put("mail.smt.auth","true");
        prop.put("mail.smtp.timeout", "25000");

        javaMailSender.setJavaMailProperties(prop);
        return javaMailSender;


    }

}
